
#include <cassert>
#include <iostream>

using namespace std;

// 相同类型最好放在一起
struct str1 { // 24
  int a;
  double b;
  char c;
};

struct str2 { // 16
  double b;
  char c;
  int a;
};

struct str3 { // 16
  double b;
  int a;
  char c;
};

struct str4 { // 24
  char c;
  double b;
  int a;
};

struct str7 { // 16
  char c;
  int a;
  double b;
};

struct str5 { // 16
  int c;
  int a;
  double b;
};

struct str6 { // 16
  double b;
  int c;
  int a;
};

struct X {  // 24
  double a; // [0, 7]
  char b;   // [8]
  int c;    // [12, 15]
  char d;   // [16]
};

struct X2 { // 24
  char b;   // [8]
  int c;    // [12, 15]
  char d;   // [16]
  double a; // [0, 7]
};

struct X3 { // 16
  char b;   // [8]
  char d;   // [16]
  int c;    // [12, 15]
  double a; // [0, 7]
};

struct X4 { // 16
  double a; // [0, 7]
  char b;   // [8]
  char d;   // [16]
  int c;    // [12, 15]
};

typedef double real_t;

struct Point {
  real_t p[3];

  Point(){};

  real_t &operator[](int i) noexcept {
    assert(-1 < i && i < 3);
    return p[i];
  }
  const real_t &operator[](int i) const noexcept {
    assert(-1 < i && i < 3);
    return p[i];
  }
  real_t &x() noexcept { return p[0]; }
  real_t &y() noexcept { return p[1]; }
  real_t &z() noexcept { return p[2]; }
  const real_t &x() const noexcept { return p[0]; }
  const real_t &y() const noexcept { return p[1]; }
  const real_t &z() const noexcept { return p[2]; }
  real_t *data() noexcept { return p; }
  const real_t *data() const noexcept { return p; }
  int size() const noexcept { return 3; }

  Point &operator/=(const real_t val) {
    p[0] /= val;
    p[1] /= val;
    p[2] /= val;
    return *this;
  }
  Point &operator+=(const Point &varp) {
    p[0] += varp[0];
    p[1] += varp[1];
    p[2] += varp[2];
    return *this;
  }
};

int main() {
  cout << "sizeof(str1)  = " << sizeof(str1) << "\n";
  cout << "sizeof(str2)  = " << sizeof(str2) << "\n";
  cout << "sizeof(bool)  = " << sizeof(bool) << "\n";
  cout << "sizeof(str3)  = " << sizeof(str3) << "\n";
  cout << "sizeof(str4)  = " << sizeof(str4) << "\n";
  cout << "sizeof(str5)  = " << sizeof(str5) << "\n";
  cout << "sizeof(str6)  = " << sizeof(str6) << "\n";
  cout << "sizeof(str7)  = " << sizeof(str7) << "\n";
  cout << "sizeof(x)  = " << sizeof(X) << "\n";
  cout << "sizeof(x2)  = " << sizeof(X2) << "\n";
  cout << "sizeof(x3)  = " << sizeof(X3) << "\n";
  cout << "sizeof(x4)  = " << sizeof(X4) << "\n";

  cout << sizeof(double) << "\n";

  Point *p;
  p = new Point[1];
  //   默认执行初始化    0 0 0
  cout << (*p)[0] << "  " << (*p)[1] << "  " << (*p)[2] << endl;

  return 0;
}